package com.wywah.controller;

import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.Map;

@RestController
public class RefreshRoutesController {
    private final ApplicationEventPublisher applicationEventPublisher;


    @GetMapping("refresh")
    public Mono<Map<String, String>> refreshRoutes() {
        HashMap<String, String> map = new HashMap<>();
        map.put("msg", "ok");

        applicationEventPublisher.publishEvent(new RefreshRoutesEvent(map));

        return Mono.just(map);
    }


    public RefreshRoutesController(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }
}
